package com.example.ruanshe3.controller;

import com.example.ruanshe3.model.*;
import com.example.ruanshe3.service.DataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@Api(tags = "API接口")
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
public class DataController {
    @Autowired
    private DataService dataService;
    //增
    @ApiOperation("添加用户信息")
    @PostMapping("/insertuser")
    public String insertuser(@RequestBody user data) {
        // @RequestBody注解用来绑定通过http请求中application/json类型上传的数据
        return dataService.insertuser(data.getUserid(),data.getUsername(),data.getPassword(),data.getPhone());
    }
    @ApiOperation("添加评论信息")
    @PostMapping("/insertreview")
    public String insertreview(@RequestBody review data) {
        // @RequestBody注解用来绑定通过http请求中application/json类型上传的数据
        return dataService.insertreview(data.getReviewid(),data.getType(),data.getObjectid(),data.getId() ,data.getContent(),data.getReviewtime());
    }
    @ApiOperation("添加上传信息")
    @PostMapping("/insertupload")
    public String insertupload(@RequestBody upload data) {
        // @RequestBody注解用来绑定通过http请求中application/json类型上传的数据
        return dataService.insertupload(data.getUploadid(),data.getType(),data.getObjectid(),data.getUploadtime());
    }
    @ApiOperation("添加点赞信息")
    @PostMapping("/insertlikes")
    public String insertlikes(@RequestBody likes data) {
        // @RequestBody注解用来绑定通过http请求中application/json类型上传的数据
        return dataService.insertlikes(data.getLikesid(),data.getType(),data.getObjectid());
    }
    @ApiOperation("添加收藏信息")
    @PostMapping("/insertcollect")
    public String insertcollect(@RequestBody collect data) {
        // @RequestBody注解用来绑定通过http请求中application/json类型上传的数据
        return dataService.insertcollect(data.getCollectid(),data.getType(),data.getObjectid());
    }
    @ApiOperation("添加个体信息")
    @PostMapping("/insertobject")
    public String insertobject(@RequestBody object data) {
        // @RequestBody注解用来绑定通过http请求中application/json类型上传的数据
        return dataService.insertobject(data.getType(),data.getObjectid(),data.getName(),data.getImage(),data.getContent(),data.getDetail());
    }

    //删
    @ApiOperation("删除指定id的用户信息")
    @DeleteMapping("/deleteuser/{userid}")
    public void deleteUser(@PathVariable int userid) {
        dataService.deleteuser(userid);
    }
    @ApiOperation("删除指定id的评论信息")
    @DeleteMapping("/deletereview/{id}")
    public void deletereview(@PathVariable int id) {
        dataService.deletereview(id);
    }
    @ApiOperation("删除指定点赞信息")
    @DeleteMapping("/deletelikes")
    public void deletelikes(@RequestBody likes data) {
        dataService.deletelikes(data);
    }
    @ApiOperation("删除指定上传信息")
    @DeleteMapping("/deleteupload")
    public void deleteupload(@RequestBody upload data) {
        dataService.deleteupload(data);
    }
    @ApiOperation("删除指定收藏信息")
    @DeleteMapping("/deletecollect")
    public void deletecollect(@RequestBody collect data) {
        dataService.deletecollect(data);
    }
    @ApiOperation("删除指定个体信息")
    @DeleteMapping("/deleteobject/{type}&&{objectid}")
    public void deleteobject(@PathVariable int type,@PathVariable int objectid) {
        dataService.deleteobject(type,objectid);
    }

    //改
    //查
    @ApiOperation("查询全部个体的所有信息")
    @GetMapping("/findObject/{type}")
    public List<object> findObject(@PathVariable int type) {
        return dataService.findObject(type);
    }
    @ApiOperation("按关键字查询个体信息")
    @GetMapping("/findObjectByKey/{key}&&{type}")
    public List<object> findObjectByKey(@PathVariable String key,@PathVariable int type) {
        return dataService.findObjectByKey(key,type);
    }
    @ApiOperation("查询后按日期升序排序的所有个体")
    @GetMapping("/findObjectByKeySortTimeAsc/{key}&&{type}")
    public List<object> findObjectByKeySortTimeAsc(@PathVariable String key,@PathVariable int type) {
        return dataService.findObjectByKeySortTimeAsc(key,type);
    }
    @ApiOperation("查询后按日期降序排序的所有个体")
    @GetMapping("/findObjectByKeySortTimeDesc/{key}&&{type}")
    public List<object> findObjectByKeySortTimeDesc(@PathVariable String key,@PathVariable int type) {
        return dataService.findObjectByKeySortTimeDesc(key,type);
    }
    @ApiOperation("查询后按收藏数升序排序的所有个体")
    @GetMapping("/findObjectByKeySortCollectAsc/{key}&&{type}")
    public List<object> findObjectByKeySortCollectAsc(@PathVariable String key,@PathVariable int type) {
        return dataService.findObjectByKeySortCollectAsc(key,type);
    }
    @ApiOperation("查询后按收藏数降序排序的所有个体")
    @GetMapping("/findObjectByKeySortCollectDesc/{key}&&{type}")
    public List<object> findObjectByKeySortCollectDesc(@PathVariable String key,@PathVariable int type) {
        return dataService.findObjectByKeySortCollectDesc(key,type);
    }
    @ApiOperation("查询后按点赞数升序排序的所有个体")
    @GetMapping("/findObjectByKeySortLikesAsc/{key}&&{type}")
    public List<object> findObjectByKeySortLikesAsc(@PathVariable String key,@PathVariable int type) {
        return dataService.findObjectByKeySortLikesAsc(key,type);
    }
    @ApiOperation("查询后按点赞数降序排序的所有个体")
    @GetMapping("/findObjectByKeySortLikesDesc/{key}&&{type}")
    public List<object> findObjectByKeySortLikesDesc(@PathVariable String key,@PathVariable int type) {
        return dataService.findObjectByKeySortLikesDesc(key,type);
    }
    @ApiOperation("查询后按评论数升序排序的所有个体")
    @GetMapping("/findObjectByKeySortReviewAsc/{key}&&{type}")
    public List<object> findObjectByKeySortReviewAsc(@PathVariable String key,@PathVariable int type) {
        return dataService.findObjectByKeySortReviewAsc(key,type);
    }
    @ApiOperation("查询后按评论数降序排序的所有个体")
    @GetMapping("/findObjectByKeySortReviewDesc/{key}&&{type}")
    public List<object> findObjectByKeySortReviewDesc(@PathVariable String key,@PathVariable int type) {
        return dataService.findObjectByKeySortReviewDesc(key,type);
    }
    @ApiOperation("按日期升序排序的所有个体")
    @GetMapping("/findObjectSortTimeAsc/{type}")
    public List<object> findObjectSortTimeAsc(@PathVariable int type) {
        return dataService.findObjectSortTimeAsc(type);
    }
    @ApiOperation("按日期降序排序的所有个体")
    @GetMapping("/findObjectSortTimeDesc/{type}")
    public List<object> findObjectSortTimeDesc(@PathVariable int type) {
        return dataService.findObjectSortTimeDesc(type);
    }
    @ApiOperation("按收藏数升序排序的所有个体")
    @GetMapping("/findObjectSortCollectAsc/{type}")
    public List<object> findObjectSortCollectAsc(@PathVariable int type) {
        return dataService.findObjectSortCollectAsc(type);
    }
    @ApiOperation("按收藏数降序排序的所有个体")
    @GetMapping("/findObjectSortCollectDesc/{type}")
    public List<object> findObjectSortCollectDesc(@PathVariable int type) {
        return dataService.findObjectSortCollectDesc(type);
    }
    @ApiOperation("按点赞数升序排序的所有个体")
    @GetMapping("/findObjectSortLikesAsc/{type}")
    public List<object> findObjectSortLikesAsc(@PathVariable int type) {
        return dataService.findObjectSortLikesAsc(type);
    }
    @ApiOperation("按点赞数降序排序的所有个体")
    @GetMapping("/findObjectSortLikesDesc/{type}")
    public List<object> findObjectSortLikesDesc(@PathVariable int type) {
        return dataService.findObjectSortLikesDesc(type);
    }
    @ApiOperation("按评论数升序排序的所有个体")
    @GetMapping("/findObjectSortReviewAsc/{type}")
    public List<object> findObjectSortReviewAsc(@PathVariable int type) {
        return dataService.findObjectSortReviewAsc(type);
    }
    @ApiOperation("按评论数降序排序的所有个体")
    @GetMapping("/findObjectSortReviewDesc/{type}")
    public List<object> findObjectSortReviewDesc(@PathVariable int type) {
        return dataService.findObjectSortReviewDesc(type);
    }
    @ApiOperation("某个个体的所有信息")
    @GetMapping("/findOnObject/{type}&&{objectid}")
    public object findOnObject(@PathVariable int type,@PathVariable int objectid) {
        return dataService.findOneObject(type, objectid);
    }
    @ApiOperation("对某个个体的评论所有信息")
    @GetMapping("/findReviewByObject/{type}&&{objectid}")
    public List<review> findReviewByObject(@PathVariable int type,@PathVariable int objectid) {
        return dataService.findReviewByObject(type, objectid);
    }
    @ApiOperation("对某个个体点赞数")
    @GetMapping("/findLikes_total/{type}&&{objectid}")
    public likes_total findLikes_total(@PathVariable int type,@PathVariable int objectid) {
        return dataService.findLikes_total(type, objectid);
    }
    @ApiOperation("对某个个体评论数")
    @GetMapping("/findReview_total/{type}&&{objectid}")
    public review_total findReview_total(@PathVariable int type,@PathVariable int objectid) {
        return dataService.findReview_total(type, objectid);
    }
    @ApiOperation("对某个个体收藏数")
    @GetMapping("/findCollect_total/{type}&&{objectid}")
    public collect_total findCollect_total(@PathVariable int type,@PathVariable int objectid) {
        return dataService.findCollect_total(type, objectid);
    }
    @ApiOperation("按关键字查询某个用户收藏的所有个体")
    @GetMapping("/findObjectByCollect/{collectid}&&{type}&&{key}")
    public List<object> findObjectByCollect(@PathVariable int collectid,@PathVariable int type,@PathVariable String key) {
        return dataService.findObjectByCollect(collectid,type,key);
    }
    @ApiOperation("查询后按日期升序排序某个用户收藏的所有个体")
    @GetMapping("/findObjectByCollectSortTimeAsc/{collectid}&&{type}&&{key}")
    public List<object> findObjectByCollectSortTimeAsc(@PathVariable int collectid,@PathVariable int type,@PathVariable String key) {
        return dataService.findObjectByCollectSortTimeAsc(collectid,type,key);
    }
    @ApiOperation("查询后按日期降序排序某个用户收藏的所有个体")
    @GetMapping("/findObjectByCollectSortTimeDesc/{collectid}&&{type}&&{key}")
    public List<object> findObjectByCollectSortTimeDesc(@PathVariable int collectid,@PathVariable int type,@PathVariable String key) {
        return dataService.findObjectByCollectSortTimeDesc(collectid,type,key);
    }
    @ApiOperation("查询后按收藏升序排序某个用户收藏的所有个体")
    @GetMapping("/findObjectByCollectSortCollectAsc/{collectid}&&{type}&&{key}")
    public List<object> findObjectByCollectSortCollectAsc(@PathVariable int collectid,@PathVariable int type,@PathVariable String key) {
        return dataService.findObjectByCollectSortCollectAsc(collectid,type,key);
    }
    @ApiOperation("查询后按收藏降序排序某个用户收藏的所有个体")
    @GetMapping("/findObjectByCollectSortCollectDesc/{collectid}&&{type}&&{key}")
    public List<object> findObjectByCollectSortCollectDesc(@PathVariable int collectid,@PathVariable int type,@PathVariable String key) {
        return dataService.findObjectByCollectSortCollectDesc(collectid,type,key);
    }
    @ApiOperation("查询后按点赞数升序排序某个用户收藏的所有个体")
    @GetMapping("/findObjectByCollectSortLikesAsc/{collectid}&&{type}&&{key}")
    public List<object> findObjectByCollectSortLikesAsc(@PathVariable int collectid,@PathVariable int type,@PathVariable String key) {
        return dataService.findObjectByCollectSortLikesAsc(collectid,type,key);
    }
    @ApiOperation("查询后按点赞数降序排序某个用户收藏的所有个体")
    @GetMapping("/findObjectByCollectSortLikesDesc/{collectid}&&{type}&&{key}")
    public List<object> findObjectByCollectSortLikesDesc(@PathVariable int collectid,@PathVariable int type,@PathVariable String key) {
        return dataService.findObjectByCollectSortLikesDesc(collectid,type,key);
    }
    @ApiOperation("查询后按评论数升序排序某个用户收藏的所有个体")
    @GetMapping("/findObjectByCollectSortReviewAsc/{collectid}&&{type}&&{key}")
    public List<object> findObjectByCollectSortReviewAsc(@PathVariable int collectid,@PathVariable int type,@PathVariable String key) {
        return dataService.findObjectByCollectSortReviewAsc(collectid,type,key);
    }
    @ApiOperation("查询后按评论数降序排序某个用户收藏的所有个体")
    @GetMapping("/findObjectByCollectSortReviewDesc/{collectid}&&{type}&&{key}")
    public List<object> findObjectByCollectSortReviewDesc(@PathVariable int collectid,@PathVariable int type,@PathVariable String key) {
        return dataService.findObjectByCollectSortReviewDesc(collectid,type,key);
    }
    @ApiOperation("通过用户id查询用户的所有信息")
    @GetMapping("/findUser/{userid}")
    public user findUser(@PathVariable int userid) {
        return dataService.findUser(userid);
    }
    @ApiOperation("通过用户名查询用户的所有信息")
    @GetMapping("/findUserByName/{username}")
    public user findUserByName(@PathVariable String username) {
        return dataService.findUserByName(username);
    }
    @ApiOperation("某用户是否点赞过某个体")
    @PostMapping("/findIfLikes")
    public likes findIfLikes(@RequestBody likes data) {
        return dataService.findIfLikes(data);
    }
    @ApiOperation("某用户是否收藏过某个体")
    @PostMapping("/findIfCollect")
    public collect findIfCollect(@RequestBody collect data) {
        return dataService.findIfCollect(data);
    }
    @ApiOperation("查询食品或笔记个体数")
    @GetMapping("/findObject_total/{type}")
    public total findObject_total(@PathVariable int type) {
        return dataService.findObject_total(type);
    }
    @ApiOperation("查询用户数")
    @GetMapping("/findUser_total")
    public total findUser_total() {
        return dataService.findUser_total();
    }
    @ApiOperation("查询某次上传信息")
    @GetMapping("/findUpload/{type}&&{objectid}")
    public upload findUpload(@PathVariable int type,@PathVariable int objectid){
        return dataService.findUpload(type, objectid);
    }
}
